import 'package:number_spark_flutter/pages/ns_home/ns_home_view.dart';
import 'package:number_spark_flutter/pages/ns_record/ns_record_view.dart';
import 'package:number_spark_flutter/style/ns_style.dart';
import 'package:number_spark_flutter/widgets/brick/ns_brick.dart';
import 'package:number_spark_flutter/widgets/ns_bottombar.dart';
import 'package:number_spark_flutter/widgets/ns_keep_alive_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../ns_mine/ns_mine_view.dart';
import 'ns_main_logic.dart';

class NSMainPage extends StatelessWidget {
  NSMainPage({Key? key}) : super(key: key);

  final logic = Get.put(NSMainLogic());

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark,
      child: Stack(
        children: [
          const NSImage(
            assetImage: 'img_bg_main.png',
            width: double.infinity,
            height: double.infinity,
            fit: BoxFit.fill,
          ),
          Scaffold(
            backgroundColor: Colors.transparent,
            body: GetBuilder<NSMainLogic>(builder: (logic) {
              return IndexedStack(
                index: logic.selectedIndex,
                children: [
                  NSKeepAliveWidget(child: NSHomePage()),
                  NSKeepAliveWidget(child: NSRecordPage()),
                  NSKeepAliveWidget(child: NSMinePage()),
                ],
              );
            }),
            bottomNavigationBar: GetBuilder<NSMainLogic>(builder: (logic) {
              return NSBottomBar(
                index: logic.selectedIndex,
                items: logic.bottomList.map((e) {
                  return NSBottomBarItem(
                    selectedImgRes: e.activeIcon,
                    unselectedImgRes: e.icon,
                    label: '',
                    imgWidth: 28.w,
                    imgHeight: 28.h,
                    onClick: (i) => logic.onSwitchBottomBar(i),
                  );
                }).toList(),
              );
            }),
          ),
        ],
      ),
    );
  }
}
